package com.sx.pipeline.ui.register

import android.view.View
import android.widget.RadioGroup
import com.alibaba.android.arouter.facade.annotation.Route
import com.gyf.immersionbar.ImmersionBar
import com.sx.pipeline.BR
import com.sx.pipeline.R
import com.sx.pipeline.app.base.CYDataBindingBaseActivity
import com.sx.pipeline.app.config.IdentityType
import com.sx.pipeline.app.config.RegisterType
import com.sx.pipeline.app.model.CYBaseViewModel
import com.sx.pipeline.arouth.RouteManager
import com.sx.pipeline.arouth.RoutePath
import com.sx.pipeline.databinding.ActSelectTypeIdRegBinding

/**
 * @Author: YY
 * @Date: 2022/4/14
 * @Description: 注册 - 选择身份类型
 */
@Route(path = RoutePath.Register.REG_SELECT_TYPE_ID)
class SelectTypeIDRegActivity: CYDataBindingBaseActivity<ActSelectTypeIdRegBinding, CYBaseViewModel>(
    R.layout.act_select_type_id_reg), View.OnClickListener, RadioGroup.OnCheckedChangeListener {

    // 注册类型
    private var registerType: Int = RegisterType.PERSONAL_REG.code
    // 注册身份
    private var identityType: Int = IdentityType.OPERATING_UNIT.code

    override fun initStatusBar() {
        ImmersionBar.with(this).statusBarDarkFont(true)
            .fitsSystemWindows(false).init()
    }

    override fun initData() {
        super.initData()
        mBinding.setVariable(BR.onClick, this)
        mBinding.setVariable(BR.onCheckedChanged, this)
    }

    override fun onCheckedChanged(group: RadioGroup, checkedId: Int) {
        when(group.id) {
            R.id.rg_register_type -> {
                // 注册类型
                when(checkedId) {
                    mBinding.rbPersonalReg.id -> {
                        this.registerType = RegisterType.PERSONAL_REG.code
                    }
                    else -> {
                        this.registerType = RegisterType.UNIT_REGISTER.code
                    }
                }
            }
            R.id.rg_register_status -> {
                // 注册身份
                when (checkedId) {
                    mBinding.rbOperateUnit.id -> {
                        this.identityType = IdentityType.OPERATING_UNIT.code
                    }
                    mBinding.rbBuildUnit.id -> {
                        this.identityType = IdentityType.BUILD_UNIT.code
                    }
                    else -> {
                        this.identityType = IdentityType.SUPPLIER.code
                    }
                }
            }
        }
    }

    override fun onClick(v: View) {
        when(v.id) {
            R.id.image_left_gray -> {
                // 返回上一级
                finish()
            }
            R.id.tv_next_step -> {
                // 下一步
                if (mBinding.rbPersonalReg.isChecked) {
                    // 如果是个人注册类型
                    RouteManager.Register.intentToRegPersonal(identityType)
                    return
                }
                // 如果是单位注册类型
                RouteManager.Register.intentToRegUnit(identityType)
            }
        }
    }

}